<template>
	<div >
		<van-nav-bar
		  class="fix_header"	
		  title="管理收货地址"
		  left-arrow
		  @click-left="onClickLeft"
		>		
		  <van-icon name="arrow-left" slot="left" color="#000" size="20"/>
	    </van-nav-bar>	
	    <div class="fix_next"></div>

         
        <div style="height: 10px;background: #f8f8f8;"></div>
	    <div class="container">
            <div class="section active">
            	<div>            	
	            	<div class="item1">
	            		<span>收货人: KILL先生</span>
	            		<span style="margin-left: 20px;">176****1570</span>
	            	</div>
	            	<div class="item2">
	            		<div style="border-bottom: 1px solid #e5e5e5;padding-bottom: 20px;">
		            		<span>收货地址:</span>
		            		<span> 江苏省 无锡市 梁溪区 中山路 888号</span>
	            		</div>
	            	</div>  
            	</div>
            	<div class="activeImg">
            		<img src="../../../../../../static/img/lanhu/06.png" alt="" style="width: 20px;height: 15px;"/>
            	</div>
            </div>  	    	
            <div class="section" v-for="item in 3">
            	<div class="item1">
            		<span>收货人: KILL先生</span>
            		<span style="margin-left: 20px;">176****1570</span>
            	</div>
            	<div class="item2">
            		<div style="border-bottom: 1px solid #e5e5e5;padding-bottom: 20px;">
	            		<span>收货地址:</span>
	            		<span> 江苏省 无锡市 梁溪区 中山路 888号</span>            			
            		</div>
            	</div>            	
            </div>            
	    </div> 	
	    
	    <div class="footerBtn">
	    	<div style="padding: 20px 37.5px;">
		    	<van-button color="#FFD630" block @click="onAdd">新增收货地址</van-button>
	    	</div>
	    </div>
	    	    
	</div>	
</template>

<script>
import {getFun} from '@/api/publicFun.js'	 
let publicFun=getFun()	
export default {	
	data() {
       return {
       	  source:'', // 绑定来源（点击的时候回到指定的地址）
       	  loading:false,
       	  finished:false,
       	  headerParams:{
       	  	pageSize:10,
       	  	pageNum:1
       	  },
       	  params:{
       	  	memberId:''
       	  },
       	  url1:'/shop/address/list',
       	  url2:'/shop/address/edit',
	      chosenAddressId: '1',
	      list: []     
       }
	},
	methods: {	
       onAdd(){
       	 this.link('/market/center/address/add')
       },
       onEdit(item){
       	 let arg='[{"addressId":"'+item.addressId+'"}]' 
         this.link('/market/center/address/edit',arg)
       },
       // 切换默认地址 (无感知)
       select(item,index){   
       	 let params={
       	 	"memberId":this.params.memberId,
       	 	"addressId":item.addressId,
       	 	"addressIsDefault":1
       	 }
       	 let that=this
		 this.$Axios.Post(this.url2,params)
		 .then(function(res) {
		 	
		 	if(that.source==1){
		 		
		 	}
		 	
	        // 切换默认的序号
	        for(var i=0;i<that.list.length;i++){
	        	that.list[i].isDefault=false
	        }
	        that.list[index].isDefault=true
		 })       	        	 
       },
       getData(){
      	let that=this	      	
	    this.$Axios.postRequest(this.url1,this.params,this.headerParams)
	    .then(function(res) {
	      if(res.data.page.current>=res.data.page.pages){
	      	that.finished=true
	      }
	      that.loading=false	
          let arr=res.data.list
          for(var i=0;i<arr.length;i++){
          	arr[i].id=arr[i].addressId
          	arr[i].name=arr[i].addressRealName
          	arr[i].tel=arr[i].addressMobile
          	arr[i].address=arr[i].addressAreaInfo+arr[i].address
          	arr[i].isDefault=arr[i].addressIsDefault>0?true:false
          	if(arr[i].addressIsDefault>0){
          		that.chosenAddressId=arr[i].addressId
          	}
          }
          that.list=that.list.concat(arr)
	    })	       	 
       },
       onLoad(){
         this.headerParams.pageNum=this.headerParams.pageNum+1
         this.getData()
       }
	},
	mixins:[publicFun],//混入		
	mounted() {
		this.params.memberId=this.$router.currentRoute.query.userId
		this.source=this.$router.currentRoute.query.source
		// this.getData()
	}
}	
</script>

<style scoped="" lang="scss">
*{color: #333;}
.section{font-size: 13px;}
.section.active{background: #e5e5e5;display: flex;}
.activeImg{display: flex;justify-content: center;align-items: center;flex: 1;img{border:1px dashed #888888;}}
.item1{margin-bottom: 17.5px;padding-top: 20px;padding-left: 15px;}
.item2{padding-left: 15px;}
.footerBtn{position: absolute;left: 0;bottom: 0;width: 100%;}

</style>